﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.DataAccess.Entities;
using RMS.Utils.MVP;
using RMS.Web.Shell.Presenter;
using RMS.Web.Shell.View;
using RMS.Utils.Navigator;

namespace RMS
{
    public partial class GetRadiologyRequestView : Page<GetRadiologyRequestPresenter>, IGetRadiologyRequestView
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FillRadiologyRequestsGriadView(0, 10);
        }

        protected void gvRadiologyRequests_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView gv = (GridView)sender;
            int RequestID = Convert.ToInt32(gv.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
            ButtonAction(e.CommandName, RequestID);
        }

        private void ButtonAction(string command, int RequestID)
        {
            if (command == "RequestDetails")
            {
                Navigator.NavigateTo(Pages.WebPagesTechnical_RequestDetailsView, new string[] { "RID=" + RequestID.ToString().Encrypt(Constants.ApplicationKey) });

            }
            else if (command == "AddImage")
            {
                Navigator.NavigateTo(Pages.WebPagesTechnical_ManageRadiologyImageView, new string [] { "RID=" + RequestID.ToString().Encrypt(Constants.ApplicationKey) });
            }
        }

        protected void Pager_PageIndexChange(object sender, EventArgs e)
        {
            FillRadiologyRequestsGriadView(Pager.CurrentStartRow, Pager.RecordsPerPage);
        }

        private void FillRadiologyRequestsGriadView(int startIndex, int lenght)
        {
            var result = this.Presenter.GetRequests(startIndex, lenght);
            Pager.TotalRecords = result.RowCount;
            gvRadiologyRequests.DataSource = result.Rows;
            gvRadiologyRequests.DataBind();

        }
    }
}